package org.infodavid.common.persistence.impl;

import javax.persistence.PersistenceException;

import org.infodavid.common.persistence.exceptions.IErrorHandler;

/**
 * The Class DefaultErrorHandler.
 */
public class DefaultErrorHandler implements IErrorHandler<PersistenceException> {

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.persistence.exceptions.IErrorHandler#handle(java.lang.Class,
	 * java.lang.Object, java.lang.Throwable)
	 */
	@SuppressWarnings("rawtypes")
	public boolean handle(final Class type, final Object id, final Throwable error)
	    throws PersistenceException {
		if (error instanceof PersistenceException) {
			throw (PersistenceException)error;
		}

		throw new PersistenceException(type.getName() + ':' + id, error);
	}
}
